/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.cms.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.xmlbeans.impl.jam.mutable.MClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.ArithUtil;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.cms.entity.Record_summary;
import com.thinkgem.jeesite.modules.cms.entity.Task;
import com.thinkgem.jeesite.modules.cms.entity.TaskDataDis;
import com.thinkgem.jeesite.modules.cms.entity.TaskOperation;
import com.thinkgem.jeesite.modules.cms.entity.TaskOprex;
import com.thinkgem.jeesite.modules.cms.entity.dayCheckUserid;
import com.thinkgem.jeesite.modules.cms.entity.dayProgress;
import com.thinkgem.jeesite.modules.cms.entity.taskData;
import com.thinkgem.jeesite.modules.cms.entity.taskDaydata;
import com.thinkgem.jeesite.modules.cms.entity.taskMonthdata;
import com.thinkgem.jeesite.modules.cms.entity.taskYeardata;
import com.thinkgem.jeesite.modules.cms.dao.Record_productDao;
import com.thinkgem.jeesite.modules.cms.dao.Record_summaryDao;
import com.thinkgem.jeesite.modules.cms.dao.TaskDao;
import com.thinkgem.jeesite.modules.cms.dao.TaskOperationDao;
import com.thinkgem.jeesite.modules.cms.dao.TaskOprexDao;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;

// TODO: Auto-generated Javadoc
/**
 * 子任务管理Service.
 *
 * @author leo
 * @version 2017-02-16
 */
@Service
@Transactional(readOnly = true)
public class TaskOperationService extends
		CrudService<TaskOperationDao, TaskOperation> {

	/** The task operation dao. */
	@Autowired
	private TaskOperationDao taskOperationDao;
	
	@Autowired
	private Record_productDao record_productDao;

	/** The summary dao. */
	@Autowired
	private Record_summaryDao summaryDao;
	@Autowired
	private TaskOprexDao taskOprexDao;
	

	/* (non-Javadoc)
	 * @see com.thinkgem.jeesite.common.service.CrudService#get(java.lang.String)
	 */
	public TaskOperation get(String id) {
		return super.get(id);
	}

	/* (non-Javadoc)
	 * @see com.thinkgem.jeesite.common.service.CrudService#findList(com.thinkgem.jeesite.common.persistence.DataEntity)
	 */
	public List<TaskOperation> findList(TaskOperation taskOperation) {
		return super.findList(taskOperation);
	}

	/* (non-Javadoc)
	 * @see com.thinkgem.jeesite.common.service.CrudService#findPage(com.thinkgem.jeesite.common.persistence.Page, com.thinkgem.jeesite.common.persistence.DataEntity)
	 */
	public Page<TaskOperation> findPage(Page<TaskOperation> page,
			TaskOperation taskOperation) {
		taskOperation.setPage(page);
		String userid =UserUtils.getUser().getLoginName();
		taskOperation.setJcdept(userid);
		page.setList(taskOperationDao.findList(taskOperation));
		taskOperation.setJcdept("");
		//page.setList(taskOperationDao.findList2(taskOperation,userid));
		return page;
		
		//return super.findPage(page, taskOperation);
	}
	public Page<TaskOperation> findPage2(Page<TaskOperation> page,
			TaskOperation taskOperation) {
		taskOperation.setPage(page);
		String userid =UserUtils.getUser().getLoginName();
		taskOperation.setJcdept(userid);
		page.setList(taskOperationDao.findList2(taskOperation));
		taskOperation.setJcdept("");
		//page.setList(taskOperationDao.findList2(taskOperation,userid));
		return page;
		
		//return super.findPage(page, taskOperation);
	}

	public Page<TaskOperation> findPageForChange(Page<TaskOperation> page,
			TaskOperation taskOperation) {
		taskOperation.setPage(page);
		String userid =UserUtils.getUser().getLoginName();
		taskOperation.setJcdept(userid);
		page.setList(taskOperationDao.findListForChange(taskOperation));
		taskOperation.setJcdept("");
		//page.setList(taskOperationDao.findList2(taskOperation,userid));
		return page;
		
		//return super.findPage(page, taskOperation);
	}

	/* (non-Javadoc)
	 * @see com.thinkgem.jeesite.common.service.CrudService#save(com.thinkgem.jeesite.common.persistence.DataEntity)
	 */
	@Transactional(readOnly = false)
	public void save(TaskOperation taskOperation) {
		if (StringUtils.isBlank(taskOperation.getId())) {
			if (taskOperation.getPdate() != null) {
				Calendar mCalendar = Calendar.getInstance();
				mCalendar.setTime(taskOperation.getPdate());
				taskOperation.setPdateYear(mCalendar.get(1));
				taskOperation
						.setPdateMonth(mCalendar.get(2) + 1);
			}
			((TaskOperationDao)this.dao).insert(taskOperation);
			
		}else{
			taskOperation.preUpdate();
			((TaskOperationDao)this.dao).update(taskOperation);
		}
			
	}

	/* (non-Javadoc)
	 * @see com.thinkgem.jeesite.common.service.CrudService#delete(com.thinkgem.jeesite.common.persistence.DataEntity)
	 */
	@Transactional(readOnly = false)
	public void delete(TaskOperation taskOperation) {
		super.delete(taskOperation);
	}
	
	/**
	 * Clear.
	 *
	 * @param end the end
	 */
	@Transactional(readOnly = false)
	public void clear(String end) {
		this.taskOperationDao.clear(end);
	}
	
	/**
	 * Gets the by keyfield.
	 *
	 * @param keyfield the keyfield
	 * @return the by keyfield
	 */
	@Transactional(readOnly = false)
	public taskData getByKeyfield(String keyfield) {
		TaskOperation taskOperation = this.taskOperationDao.getByKeyfield(keyfield);
		if (taskOperation != null) {
			taskData data = new taskData(keyfield);
			data.setCharacter01(taskOperation.getCharacter01());
			data.setCharacter02(taskOperation.getCharacter02());
			data.setCharacter03(taskOperation.getCharacter03());
			data.setCharacter04(taskOperation.getCharacter04());
			data.setCharacter05(taskOperation.getCharacter05());
			data.setCharacter06(taskOperation.getCharacter06());
			data.setCommenttext(taskOperation.getCommenttext());
			data.setDept(taskOperation.getDept());
			data.setDptask(taskOperation.getDptask());
			data.setProdqty(taskOperation.getProdqty());
			data.setA(taskOperation.getA());
			data.setB(taskOperation.getB());
			data.setC(taskOperation.getC());
			data.setD(taskOperation.getD());
			data.setE(taskOperation.getE());
			data.setF(taskOperation.getF());
			data.setG(taskOperation.getG());
			data.setH(taskOperation.getH());
			data.setIsok(taskOperation.getIsok());
			data.setIspartcomplete(taskOperation.getIspartcomplete());
			data.setIsqctask(taskOperation.getIsqctask());
			data.setIsstart(taskOperation.getIsstart());
			data.setIstagprocess(taskOperation.getIstagprocess());
			data.setIstaskcomplete(taskOperation.getIstaskcomplete());
			data.setJcdept(taskOperation.getJcdept());
			data.setNumber03(taskOperation.getNumber03());
			data.setNumber07(taskOperation.getNumber07());
			data.setNumber13(taskOperation.getNumber13());
			data.setOpcode(taskOperation.getOpcode());
			data.setOpdesc(taskOperation.getOpdesc());
			data.setPartnum(taskOperation.getPartnum());
			data.setProdcode(taskOperation.getProdcode());
			data.setProductid(taskOperation.getProductid());
			data.setProductname(taskOperation.getProductname());
			data.setStarhour(taskOperation.getStarhour());
			data.setTasktype(taskOperation.getTasktype());
			data.setUserid(taskOperation.getUserid());
			data.setXpartnum(taskOperation.getXpartnum());
			return data;
		}
		return null;
	}

	/**
	 * Gets the by keyfield 2.
	 *
	 * @param keyfield the keyfield
	 * @return the by keyfield 2
	 */
	@Transactional(readOnly = false)
	public TaskOperation getByKeyfield2(String keyfield) {
		TaskOperation t = this.taskOperationDao.getByKeyfield(keyfield);
		
		return t;
	}

	public boolean getProdOk(String productid) {
		// TODO Auto-generated method stub
		List<Boolean> list = record_productDao.getProdOk(productid);
		if(list.size()>0){
			return list.get(0);
		}
		return true;
	}

	/**
	 * Gets the no end.
	 *
	 * @return the no end
	 */
	@Transactional(readOnly = false)
	public List<TaskOperation> getNoEnd() {
		return this.taskOperationDao.getNoEnd();
	}

	/**
	 * Gets the by productid.
	 *
	 * @param productid the productid
	 * @return the by productid
	 */
	@Transactional(readOnly = false)
	public taskData getByProductid(String productid) {
		TaskOperation taskOperation = this.taskOperationDao.getByProductid(productid);
		if (taskOperation != null) {
			taskData data = inittaskdata(taskOperation);
			return data;
		}
		return null;
	}
	
	
	@Transactional(readOnly = false)
	public List<taskData> getByProdid(String productid) {
		List<TaskOperation> list = this.taskOperationDao.getByProdid(productid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation taskOperation : list) {
			if (taskOperation != null) {
				taskData data = inittaskdata(taskOperation);
				list2.add(data);
			}
		}
		
		return list2;
	}
	
	@Transactional(readOnly = false)
	public List<taskData> getByProdid2(String productid) {
		List<TaskOperation> list = this.taskOperationDao.getByProdid2(productid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation taskOperation : list) {
			if (taskOperation != null) {
				taskData data = inittaskdata(taskOperation);
				list2.add(data);
			}
		}
		
		return list2;
	}

	private taskData inittaskdata(TaskOperation t) {
		taskData data = new taskData("");
		data.setKeyfield(t.getKeyfield());
		data.setCharacter01(t.getCharacter01());
		data.setCharacter02(t.getCharacter02());
		data.setCharacter03(t.getCharacter03());
		data.setCharacter04(t.getCharacter04());
		data.setCharacter05(t.getCharacter05());
		data.setCharacter06(t.getCharacter06());
		data.setCommenttext(t.getCommenttext());
		data.setDept(t.getDept());
		data.setDptask(t.getDptask());
		data.setProdqty(t.getProdqty());
		data.setA(t.getA());
		data.setB(t.getB());
		data.setC(t.getC());
		data.setD(t.getD());
		data.setE(t.getE());
		data.setF(t.getF());
		data.setG(t.getG());
		data.setH(t.getH());
		data.setPdate(t.getPdate().toString());
		data.setIsok(t.getIsok());
		data.setIspartcomplete(t.getIspartcomplete());
		data.setIsqctask(t.getIsqctask());
		data.setIsstart(t.getIsstart());
		data.setIstagprocess(t.getIstagprocess());
		data.setIstaskcomplete(t.getIstaskcomplete());
		data.setJcdept(t.getJcdept());
		data.setNumber03(t.getNumber03());
		data.setNumber07(t.getNumber07());
		data.setNumber13(t.getNumber13());
		data.setOpcode(t.getOpcode());
		data.setOpdesc(t.getOpdesc());
		data.setPartnum(t.getPartnum());
		data.setProdcode(t.getProdcode());
		data.setProductid(t.getProductid());
		data.setProductname(t.getProductname());
		data.setStarhour(t.getStarhour());
		data.setTasktype(t.getTasktype());
		data.setUserid(t.getUserid());
		data.setXpartnum(t.getXpartnum());
		return data;
	}

	/**
	 * Checks for start.
	 *
	 * @param productid the productid
	 * @return true, if successful
	 */
	@Transactional(readOnly = false)
	public boolean hasStart(String productid) {
		TaskOperation taskOperation = this.taskOperationDao.getStartProductid(productid);
		return taskOperation != null;
	}

	/**
	 * Start.
	 *
	 * @param keyfield the keyfield
	 * @param userid the userid
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int start(String keyfield, String userid) {
		return this.taskOperationDao.updateIsStart(keyfield, 1, userid);
	}

	/**
	 * Complete.
	 *
	 * @param keyfield the keyfield
	 * @param userid the userid
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int complete(String keyfield, String userid) {
		return this.taskOperationDao.updateIsTaskComplete(keyfield, 1, userid);
	}
	
	@Transactional(readOnly = false)
	public int productcomplete(String keyfield, String userid) {
		return this.taskOperationDao.updateproductcomplete(keyfield);
	}

	/**
	 * Partcomplete.
	 *
	 * @param keyfield the keyfield
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int partcomplete(String keyfield) {
		return this.taskOperationDao.updateIsPartComplete(keyfield);
	}

	/**
	 * Qc complete.
	 *
	 * @param keyfield the keyfield
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int qcComplete(String keyfield) {
		return this.taskOperationDao.updateIsTaskQcComplete(keyfield, 1);
	}

	/**
	 * Back.
	 *
	 * @param keyfield the keyfield
	 * @param userid the userid
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int back(String keyfield, String userid) {
		return this.taskOperationDao.updateIsTaskQcComplete(keyfield, 0);
	}

	/**
	 * Update product.
	 *
	 * @param productid the productid
	 * @param isok the isok
	 * @return the int
	 */
	@Transactional(readOnly = false)
	public int updateProduct(String productid, int isok) {
		if (isok == 1) {
			return this.taskOperationDao.updateOk(productid);
		}
		return this.taskOperationDao.updateNoOk(productid);
	}

	/**
	 * Gets the yeardata.
	 *
	 * @param userid the userid
	 * @return the yeardata
	 */
	@Transactional(readOnly = false)
	public taskYeardata getYeardata(String userid) {
		Calendar cal = Calendar.getInstance();
		taskYeardata data = new taskYeardata();
		List<TaskOperation> taskOperations = this.taskOperationDao.getYeardata(userid, cal.get(1));
		int totalnum = 0;
		int num1 = 0;
		int num2 = 0;
		int num3 = 0;
		int num4 = 0;
		int num5 = 0;
		int num6 = 0;
		int num7 = 0;
		int num8 = 0;
		int num9 = 0;
		int num10 = 0;
		int num11 = 0;
		int num12 = 0;
		double totalgdp = 0.0D;
		double gdp1 = 0.0D;
		double gdp2 = 0.0D;
		double gdp3 = 0.0D;
		double gdp4 = 0.0D;
		double gdp5 = 0.0D;
		double gdp6 = 0.0D;
		double gdp7 = 0.0D;
		double gdp8 = 0.0D;
		double gdp9 = 0.0D;
		double gdp10 = 0.0D;
		double gdp11 = 0.0D;
		double gdp12 = 0.0D;

		List<Record_summary> summary = this.summaryDao.getSureMonth(userid,
				cal.get(1));
		for (TaskOperation taskOperation : taskOperations) {
			totalnum++;
			totalgdp = ArithUtil.add(totalgdp, getgdpABC(taskOperation));
			cal.setTime(taskOperation.getPdate());
			int month = cal.get(2) + 1;
			switch (month) {
			case 1:
				num1++;
				gdp1 = ArithUtil.add(gdp1, getgdpABC(taskOperation));
				break;
			case 2:
				num2++;
				gdp2 = ArithUtil.add(gdp2, getgdpABC(taskOperation));
				break;
			case 3:
				num3++;
				gdp3 = ArithUtil.add(gdp3, getgdpABC(taskOperation));
				break;
			case 4:
				num4++;
				gdp4 = ArithUtil.add(gdp4, getgdpABC(taskOperation));
				break;
			case 5:
				num5++;
				gdp5 = ArithUtil.add(gdp5, getgdpABC(taskOperation));
				break;
			case 6:
				num6++;
				gdp6 = ArithUtil.add(gdp6, getgdpABC(taskOperation));
				break;
			case 7:
				num7++;
				gdp7 = ArithUtil.add(gdp7, getgdpABC(taskOperation));
				break;
			case 8:
				num8++;
				gdp8 = ArithUtil.add(gdp8, getgdpABC(taskOperation));
				break;
			case 9:
				num9++;
				gdp1 = ArithUtil.add(gdp1, getgdpABC(taskOperation));
				break;
			case 10:
				num10++;
				gdp10 = ArithUtil.add(gdp10, getgdpABC(taskOperation));
				break;
			case 11:
				num11++;
				gdp11 = ArithUtil.add(gdp11, getgdpABC(taskOperation));
				break;
			case 12:
				num12++;
				gdp12 = ArithUtil.add(gdp12, getgdpABC(taskOperation));
			}
		}
		data.setTotalnum(totalnum);
		data.setTotalgdp(totalgdp);
		data.setNum1(num1);
		data.setGdp1(gdp1);
		data.setNum2(num2);
		data.setGdp2(gdp2);
		data.setNum3(num3);
		data.setGdp3(gdp3);
		data.setNum4(num4);
		data.setGdp4(gdp4);
		data.setNum5(num5);
		data.setGdp5(gdp5);
		data.setNum6(num6);
		data.setGdp6(gdp6);
		data.setNum7(num7);
		data.setGdp7(gdp7);
		data.setNum8(num8);
		data.setGdp8(gdp8);
		data.setNum9(num9);
		data.setGdp9(gdp9);
		data.setNum10(num10);
		data.setGdp10(gdp10);
		data.setNum11(num11);
		data.setGdp11(gdp11);
		data.setNum12(num12);
		data.setGdp12(gdp12);
		for (Record_summary s : summary) {
			switch (s.getConfirmmonth()) {
			case 1:
				data.setSure1(1);
				break;
			case 2:
				data.setSure2(1);
				break;
			case 3:
				data.setSure3(1);
				break;
			case 4:
				data.setSure4(1);
				break;
			case 5:
				data.setSure5(1);
				break;
			case 6:
				data.setSure6(1);
				break;
			case 7:
				data.setSure7(1);
				break;
			case 8:
				data.setSure8(1);
				break;
			case 9:
				data.setSure9(1);
				break;
			case 10:
				data.setSure10(1);
				break;
			case 11:
				data.setSure11(1);
				break;
			case 12:
				data.setSure12(1);
			}
		}
		return data;
	}
	
	/**
	 * Gets the gdp ABC.
	 *
	 * @param taskOperation the task operation
	 * @return the gdp ABC
	 */
	@Transactional(readOnly = false)
	private double getgdpABC(TaskOperation taskOperation) {
		return taskOperation.getA() + taskOperation.getB() + taskOperation.getC() + taskOperation.getD()
				+ taskOperation.getE() + taskOperation.getF() + taskOperation.getG() + taskOperation.getH();
	}

	/**
	 * Gets the monthdata.
	 *
	 * @param userid the userid
	 * @return the monthdata
	 */
	@Transactional(readOnly = false)
	public taskMonthdata getMonthdata(String userid) {
		Calendar cal = Calendar.getInstance();
		taskMonthdata data = new taskMonthdata();
		List<taskDaydata> taskDaydatas = this.taskOperationDao.getMonthdata(userid, cal.get(1),
				String.valueOf(cal.get(2) + 1));
		data.setDays(taskDaydatas);
		int num = 0;
		double gdp = 0.0D;
		for (taskDaydata d : taskDaydatas) {
			num += d.getTotalnum();
			gdp = ArithUtil.add(gdp, d.getTotalgdp());
		}
		data.setTotalnum(num);
		data.setTotalgdp(gdp);
		return data;
	}

	/**
	 * Gets the daydata.
	 *
	 * @param userid the userid
	 * @return the daydata
	 */
	@Transactional(readOnly = false)
	public List<taskData> getDaydata(String userid) {
		Date now = new Date();
		DateFormat d2 = DateFormat.getDateInstance();
		String str2 = d2.format(now);
		List<TaskOperation> taskOperations = this.taskOperationDao.getDaydata(userid, str2);
		List<taskData> datas = new ArrayList();
		if (taskOperations != null) {
			for (TaskOperation taskOperation : taskOperations) {
				taskData data = new taskData("");
				data.setA(taskOperation.getA());
				data.setB(taskOperation.getB());
				data.setC(taskOperation.getC());
				data.setD(taskOperation.getD());
				data.setE(taskOperation.getE());
				data.setF(taskOperation.getF());
				data.setG(taskOperation.getG());
				data.setH(taskOperation.getH());
				data.setProdqty(taskOperation.getProdqty());
				data.setOpdesc(taskOperation.getOpdesc());
				data.setKeyfield(taskOperation.getKeyfield());
				data.setPdate(d2.format(taskOperation.getPdate()));
				datas.add(data);
			}
		}
		return datas;
	}
	
	@Transactional(readOnly = false)
	public List<taskData> getnostartdata(String userid) {
		Date now = new Date();
		DateFormat d2 = DateFormat.getDateInstance();
		String str2 = d2.format(now);
		Date now2 = new Date();
		now2.setYear(-20);
		List<TaskOperation> taskOperations = this.taskOperationDao.getnostartdata(userid,now2,now);
		List<taskData> datas = new ArrayList();
		if (taskOperations != null) {
			for (TaskOperation taskOperation : taskOperations) {
				taskData data = new taskData("");
				data.setA(taskOperation.getA());
				data.setB(taskOperation.getB());
				data.setC(taskOperation.getC());
				data.setD(taskOperation.getD());
				data.setE(taskOperation.getE());
				data.setF(taskOperation.getF());
				data.setG(taskOperation.getG());
				data.setH(taskOperation.getH());
				data.setIsok(taskOperation.getIsok());
				data.setProductname(taskOperation.getProductname());
				data.setDptask(taskOperation.getDptask());
				data.setProdqty(taskOperation.getProdqty());
				data.setOpdesc(taskOperation.getOpdesc());
				data.setKeyfield(taskOperation.getKeyfield());
				data.setPdate(d2.format(taskOperation.getPdate()));
				datas.add(data);
			}
		}
		return datas;
	}
	@Transactional(readOnly = false)
	public List<taskData> getisstartnoend(String userid) {
		Date now = new Date();
		DateFormat d2 = DateFormat.getDateInstance();
		String str2 = d2.format(now);
		List<TaskOperation> taskOperations = this.taskOperationDao.getisstartnoend(userid);
		List<taskData> datas = new ArrayList();
		if (taskOperations != null) {
			for (TaskOperation taskOperation : taskOperations) {
				taskData data = new taskData("");
				data.setA(taskOperation.getA());
				data.setB(taskOperation.getB());
				data.setC(taskOperation.getC());
				data.setD(taskOperation.getD());
				data.setE(taskOperation.getE());
				data.setF(taskOperation.getF());
				data.setG(taskOperation.getG());
				data.setH(taskOperation.getH());
				data.setIsok(taskOperation.getIsok());
				data.setProductname(taskOperation.getProductname());
				data.setDptask(taskOperation.getDptask());
				data.setOpdesc(taskOperation.getOpdesc());
				data.setProdqty(taskOperation.getProdqty());
				data.setKeyfield(taskOperation.getKeyfield());
				data.setPdate(d2.format(taskOperation.getPdate()));
				datas.add(data);
			}
		}
		return datas;
	}
	
	
	
	public List<TaskDataDis> gettodaydtlbyuserid(String today,String userid) {
		//Date now = new Date(today);
		DateFormat d2 = DateFormat.getDateInstance();
		Date now = new Date();
		try {
			now = d2.parse(today);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//List<TaskDataDis> datas = this.taskOperationDao.getnostartdata2(userid,now2,now);
		List<TaskDataDis> datas = this.taskOperationDao.gettodaydtlbyuserid(userid,now);
		return datas;
	}
	
	public List<TaskDataDis> getnostartdata2(String userid) {
		Date now = new Date();
		DateFormat d2 = DateFormat.getDateInstance();
		String str2 = d2.format(now);
		Date now2 = new Date();
		now2.setYear(-20);
		List<TaskDataDis> datas = this.taskOperationDao.getnostartdata2(userid,now2,now);
		return datas;
	}
	
	public List<TaskDataDis> getisstartnoend2(String userid) {
		Date now = new Date();
		DateFormat d2 = DateFormat.getDateInstance();
		String str2 = d2.format(now);
		List<TaskDataDis> datas = this.taskOperationDao.getisstartnoend2(userid);
		return datas;
	}
	
	/**
	 * Find list.
	 *
	 * @param split the split
	 * @return the list
	 */
	public List<TaskOperation> findList(String[] split) {
		
		return ((TaskOperationDao)dao).findListIn(split);
	}

	public List<taskData> getTastByPN(String productid,String userid) {
		List<TaskOperation> list1  = ((TaskOperationDao)dao).findListByPNUid(productid,userid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation t2 : list1) {
			taskData data = new taskData(t2.getKeyfield());
			data.setKeyfield(t2.getKeyfield());
			data.setProductid(t2.getProductid());
			data.setProdqty(t2.getProdqty());
			data.setProductname(t2.getProductname());
			data.setOpdesc(t2.getOpdesc());
			data.setOpcode(t2.getOpcode());
			data.setDptask(t2.getDptask());
			//data =inittaskdata(t2);
			list2.add(data);
		}
		return list2;
	}
	
	public List<taskData> getByPNAndTcompl(String productid,String userid) {
		List<TaskOperation> list1  = ((TaskOperationDao)dao).getByPNAndTcompl(productid,userid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation t2 : list1) {
			taskData data = new taskData(t2.getKeyfield());
			data.setKeyfield(t2.getKeyfield());
			data.setProductid(t2.getProductid());
			data.setProductname(t2.getProductname());
			data.setProdqty(t2.getProdqty());
			data.setOpdesc(t2.getOpdesc());
			data.setOpcode(t2.getOpcode());
			data.setIsstart(t2.getIsstart());
			data.setIstaskcomplete(t2.getIstaskcomplete());
			data.setDptask(t2.getDptask());
			//data =inittaskdata(t2);
			list2.add(data);
		}
		return list2;
	}
	
	public List<taskData> getByGroupIdStart(String groupid,String userid) {
		List<TaskOperation> list1  = ((TaskOperationDao)dao).getByGroupIdStart(groupid,userid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation t2 : list1) {
			taskData data = new taskData(t2.getKeyfield());
			data.setKeyfield(t2.getKeyfield());
			data.setProductid(t2.getProductid());
			data.setProductname(t2.getProductname());
			data.setProdqty(t2.getProdqty());
			data.setOpdesc(t2.getOpdesc());
			data.setOpcode(t2.getOpcode());
			data.setDptask(t2.getDptask());
			//data =inittaskdata(t2);
//			//限制调剂:任务未完成Istaskcomplete = false   没有开始的任务isstart= false  没有冻结isok=false  [产品是否合格 isok=false(合格) true(不合格)]
//			if (t2.getIstaskcomplete() ==false  && t2.getIsstart() ==false && t2.getIsok() == false  ){
//				list2.add(data);
//			}
			list2.add(data);
		}
		return list2;
	}
	
	public List<taskData> getByGroupIdEnd(String groupid) {
		List<TaskOperation> list1  = ((TaskOperationDao)dao).getByGroupIdEnd(groupid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation t2 : list1) {
			taskData data = new taskData(t2.getKeyfield());
			data.setKeyfield(t2.getKeyfield());
			data.setProductid(t2.getProductid());
			data.setProductname(t2.getProductname());
			data.setProdqty(t2.getProdqty());
			data.setOpdesc(t2.getOpdesc());
			data.setOpcode(t2.getOpcode());
			data.setDptask(t2.getDptask());
			//data =inittaskdata(t2);
//			//限制调剂:任务未完成Istaskcomplete = false   没有开始的任务isstart= false  没有冻结isok=false  [产品是否合格 isok=false(合格) true(不合格)]
//			if (t2.getIstaskcomplete() ==false  && t2.getIsstart() ==false && t2.getIsok() == false  ){
//				list2.add(data);
//			}
			list2.add(data);
		}
		return list2;
	}
	public List<taskData> getByGroupId(String groupid) {
		List<TaskOperation> list1  = ((TaskOperationDao)dao).getByGroupId(groupid);
		List<taskData> list2 = new ArrayList();
		for (TaskOperation t2 : list1) {
			taskData data = new taskData(t2.getKeyfield());
			data =inittaskdata(t2);
			list2.add(data);
		}
		return list2;
	}
	
	
	public List<dayCheckUserid> dayCheckUidData(Date pdate) {
		return ((TaskOperationDao)dao).daycheckuiddata(pdate);
	}
	
	public List<dayProgress> dayProgressData(Date pdate) {
		String sql="";
		StringBuilder sb = new StringBuilder();
//		sb.append("select a.*,b.isstart2,c.iscompl2 from ( ");
//		sb.append("select pdate,jcdept,dept,count(id) as 'all',sum(isstart=1 and istaskcomplete=0 ) as 'isstartuncompl' , ");
//		sb.append("sum(istaskcomplete=1 ) as 'iscompl' ,sum(isstart=0 ) as 'unstart' ,sum(isok=1) as 'unok', ");
//		sb.append(String.format("sum(isnull(userid)) as 'un' from bll_taskoperation where pdate='{0}' group by pdate,jcdept,dept ) a  ", pdate.toString()));
//		sb.append("left join ( ");
//		sb.append(String.format("select jcdept,dept,count(id) as 'all',sum(isstart=1 ) as 'isstart2'  from bll_taskoperation where pdate<>'{0}' and keyfield in  ", pdate.toString()));
//		sb.append(String.format("(select distinct keyfield  FROM bll_records where type ='S'  and date='{0}') group by jcdept,dept) b ", pdate.toString()));
//		sb.append("on a.jcdept=b.jcdept ");
//		sb.append("left join ( ");
//		sb.append(String.format("select jcdept,dept,count(id) as 'all',sum(istaskcomplete=1 ) as 'iscompl2'  from bll_taskoperation where pdate<>'{0}' and keyfield in  ", pdate.toString()));
//		sb.append(String.format("(select distinct keyfield  FROM bll_records where type ='E'  and date='{0}' group by jcdept,dept) c ", pdate.toString()));
//		sb.append("on a.jcdept=c.jcdept  ");
		SimpleDateFormat s  = new SimpleDateFormat("yyyy-MM-dd");
		String ss = s.format(pdate);
		//sb.append(String.format("call day_progress_data('%s')",ss));
		sb.append(ss);
		sql = sb.toString();
		return ((TaskOperationDao)dao).dayProgressdata(sql);
	}

	public List<TaskOperation> getTaskByDateDept(Date pdate, String deptid) {
		List<TaskOperation> list = ((TaskOperationDao)dao).getTaskByDateDept(pdate, deptid);
		return  list;
	}

	public boolean istaskcompleteByPid(String productid) {
		boolean iscompl = false;
		Integer uncompl = ((TaskOperationDao)dao).istaskcompleteByPid(productid);
		if (uncompl==0){
			iscompl =true;
		}
		return iscompl;
	}
	@Transactional(readOnly = false)
	public void addTaskOprEx(String id, String userid, Double gdp) {
		// TODO Auto-generated method stub
		TaskOprex t = new TaskOprex();
		int taskid =0;
		try {
			taskid = Integer.parseInt(id);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		t.setTaskid(taskid);
		t.setUserid(userid);
		Date d = new Date();
		t.setComfirmdate(d);
		t.setComfirmtime(d);
		t.setComfirmed(true);
		t.setAmount(gdp);
		taskOprexDao.insert(t);
	}
	
}